package com.hucheng.seckill.vo;

import com.hucheng.seckill.entity.SeckillOrderDO;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.format.DateTimeFormatter;

/**
 * @Author: 凉白开不加冰
 * @Version: 0.0.1V
 * @Date: 2019-06-25
 * @Description: 返回参数
 **/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class SeckillOrderVO {
    private Integer seckillOrderId;
    private Integer userId;
    private Integer orderId;
    private Integer goodsId;
    private String dateCreated;
    private String dateUpdated;

    public static SeckillOrderVO buildSeckillGoodsVO(final SeckillOrderDO seckillOrderDO) {
        if (seckillOrderDO == null) {
            return null;
        }
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        return new SeckillOrderVO(seckillOrderDO.getSeckillOrderId(),
                seckillOrderDO.getUserId(),
                seckillOrderDO.getOrderId(),
                seckillOrderDO.getGoodsId(),
                dateTimeFormatter.format(seckillOrderDO.getSeckillOrderDateCreated().toLocalDateTime()),
                dateTimeFormatter.format(seckillOrderDO.getSeckillOrderDateUpdated().toLocalDateTime()));
    }
}
